<?php
!defined('DEBUG') AND exit('Forbidden');
$threadext_cfg = null;
if(!function_exists('get_plugin_config')){
    require dirname(__FILE__).DIRECTORY_SEPARATOR.'model'.DIRECTORY_SEPARATOR.'threadext.func.php';
}
$threadext_cfg = &get_plugin_config(empty($dir)?__FILE__:$dir);
$threadext_tb = 'threadext';
$postflag_tb = 'postflag';
$label_tb = 'label';
$labelog_tb = 'labelog';
if(!empty($threadext_cfg['ThreadextTable']))  $threadext_tb = $threadext_cfg['ThreadextTable'];
if(!empty($threadext_cfg['Label']['LabelTable']))  $label_tb = $threadext_cfg['Label']['LabelTable'];
if(!empty($threadext_cfg['Label']['LabellogTable']))  $labelog_tb = $threadext_cfg['Label']['LabellogTable'];
if(!empty($threadext_cfg['PostFlag']['table']))  $postflag_tb = $threadext_cfg['PostFlag']['table'];
$tablepre = $db->tablepre;


$sql = "DROP TABLE IF EXISTS {$tablepre}{$threadext_tb};
DROP TABLE IF EXISTS {$tablepre}{$postflag_tb};
DROP TABLE IF EXISTS {$tablepre}{$label_tb};
DROP TABLE IF EXISTS {$tablepre}{$labelog_tb}0;";
$r = db_exec($sql);

//删除所有分表:
for($i=1;$i<1024;$i++){
    $r2x = db_sql_find_one('select count(*) from `'.$tablepre.$labelog_tb.$i.'`');
    if($r2x !== false){
        $sql2 = "DROP TABLE IF EXISTS {$tablepre}{$labelog_tb}{$i};";
        $r2x = db_exec($sql2);
    }
    if($r2x === false) break;
}

$sql = "ALTER TABLE `{$tablepre}thread`  DROP `trank`;
ALTER TABLE `{$tablepre}post`  DROP `prank`;";
$r2 = db_exec($sql);
//删除本插件全部缓存:
$delcaches = ClearCacheFor();
